<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
*{margin: 0px;padding: 0px; overflow: hidden;}
a{color:#D1D1D1;}
a:HOVER{color:black;}
#paging_id{ 
	position: absolute;
	right:50px;
	bottom:50px;
}
#paging_id #initnum_id{width:20px;}
#table_1{ width:99%; }
#table_1 td{padding:5px 0px;}
#table_2{border:1px solid black;width:99%;border-collapse:collapse; }
#table_2 td{border:1px solid black;padding:5px 0px;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查询商品列表</title>
<script type="text/javascript">
	function deletItems(){
		var bln = document.getElementsByName("items_id");
		for ( var i = 0; i < bln.length; i++) {
			if(bln[i].checked==true){
				document.itemsForm2.action="${pageContext.request.contextPath }/items/deletItems.action";
				document.itemsForm2.submit();
				return;}
		}
		alert("请选择操作的商品！");
	}
	
	function queryItems(){
		document.itemsForm.action="${pageContext.request.contextPath }/items/queryItems.action?pageNow=1&pageSize=12";
		document.itemsForm.submit();
	}
	
	function editItemsQuery(){
		var bln = document.getElementsByName("items_id");
		for ( var i = 0; i < bln.length; i++) {
			if(bln[i].checked==true){
				document.itemsForm2.action="${pageContext.request.contextPath }/items/editItemsQuery.action";
				document.itemsForm2.submit();
				return;}
		}
		alert("请选择操作的商品！");
	}
	function pageup(){
		var pageNow =document.getElementById("initnum_id").value;
		if(pageNow!=""){
			pageNow = parseInt(document.getElementById("initnum_id").value);
		}else{pageNow=1;}
		if(pageNow>1){pageNow--;}else{return;}
		document.getElementById("initnum_id").value=pageNow;
		document.itemsForm2.action="${pageContext.request.contextPath }/items/queryItems.action";
		document.itemsForm2.submit();
	}
	
	function pagedown(){
		var pageNow =document.getElementById("initnum_id").value;
		var totalPageCount = document.getElementById("totalPageCount_id").value;		

		if(pageNow!=""){
			pageNow = parseInt(document.getElementById("initnum_id").value);
		}else{pageNow=0;}
		pageNow++;
		if(pageNow>totalPageCount){pageNow=totalPageCount;return;}
		document.getElementById("initnum_id").value=pageNow;
		document.itemsForm2.action="${pageContext.request.contextPath }/items/queryItems.action";
		document.itemsForm2.submit();
	}
	function page_write(){
		var pageNow =document.getElementById("initnum_id").value;
		if(pageNow!=""){
			pageNow = parseInt(document.getElementById("initnum_id").value);
		}else{pageNow=1;}
		
		document.getElementById("initnum_id").value=pageNow;
		document.itemsForm2.action="${pageContext.request.contextPath }/items/queryItems.action";
		document.itemsForm2.submit();
	}
</script>
</head>
<body>
<form name="itemsForm"  action="${pageContext.request.contextPath }/items/queryItems.action" method="post">
<table id="table_1">
<tr>
<td>
商品名称：<input type="text" name="itemsCustom.name"/>
商品类型：
<select name="itemsCustom.producttype">
	<option value=" ">--请选择--</option>			
	<c:forEach items="${itemtypes}" var="itemtype">
		<option value="${itemtype.key}">${itemtype.value}</option>		
	</c:forEach>
</select>
</td>
<td><input type="button" value="查询" onclick="queryItems()"/>
	<input type="button" value="删&nbsp;除" onclick=" deletItems()"/>
	<!-- <input type="button" value="批量修改" onclick="editItemsQuery()"/> -->
	
</td>
</tr>
</table>
</form>

<form name="itemsForm2"  action="${pageContext.request.contextPath }/items/queryItems.action" method="post">
<table id="table_2" >
<tr>
	<td style="width:40px;text-align: center;">选择</td>
	<td>商品类型</td>
	<td>商品名称</td>
	<td>商品价格</td>
	<td>商品描述</td>
	<td>操作</td>
</tr>
<c:forEach items="${itemsList}" var="items">
<tr>
	<td style="width: 40px;text-align: center;"><input type="checkbox" name="items_id" value="${items.id}"></td>
	<td>${items.producttype}</td>
	<td>${items.name}</td>
	<td>${items.price}</td>
	<td>${items.detail}</td>
	<td style="width:40px;text-align: center;"><a href="${pageContext.request.contextPath}/items/editItems.action?id=${items.id}">修改</a></td>
</tr>
</c:forEach>
</table>
	<div id="paging_id">
		<input type="button" value="上一页" onclick="pageup()"/>
		<input type="button" value="下一页" onclick="pagedown()"/>
		<input type="text" name="pageSize" value="12" style="display: none;"/>
		<input type="text" name="itemsCustom.producttype" value="${$producttype}" style="display: none;"/>
		<input type="text" id="totalPageCount_id" value="${$totalPageCount}" style="display: none;"/>
		<input type="text" name="itemsCustom.name" value="${$name}" style="display: none;"/>
		<input type="text" id="initnum_id" name="pageNow" value="${$pageNow}"/>/<span>${$totalPageCount}</span>页
		<input type="button" value="go" onclick="page_write()"/>
		</div>
</form>
</body>
</html>